/*

This file is part of org-json.

org-json is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

using System;
using NUnit.Framework;
using System.Collections.Generic;
using System.Text;
using Org.JSON.Output;
using Org;

namespace Org.JSON.Test
{
	[TestFixture()]
	public class Serialization
	{
		[Test()]
		public void Null ()
		{
			var value = new JSON.Null();
			Assert.AreEqual("null", value.ToString());
		}
		
		[Test()]
		public void BooleanTrue()
		{
			var value = (JSON.Value) true;
			Assert.AreEqual("true", value.ToString());
		}
		
		[Test()]
		public void BooleanFalse()
		{
			var value = (JSON.Boolean) false;
			Assert.AreEqual("false", value.ToString());
		}
		
		[Test()]
		public void StringBasic()
		{
			var value = (JSON.String) "hello";
			Assert.AreEqual("\"hello\"", value.ToString());
		}
		
		[Test()]
		public void StringWithQuotes()
		{
			var value = (JSON.String) "\"hello\"";
			Assert.AreEqual("\"\\\"hello\\\"\"", value.ToString());
		}
		[Test()]
		public void StringMixedScape()
		{
			var value = (JSON.String)"\\\t\n\b\f\r";
			Assert.AreEqual("\"\\\\\\t\\n\\b\\f\\r\"", value.ToString());
		}
		[Test()]
		public void StringControlScape()
		{
			var value = (JSON.String)"\u0000\u001f";
			Assert.AreEqual("\"\\u0000\\u001f\"", value.ToString().ToLower());
		}
		
		[Test()]
		public void ArrayEmpty()
		{
			var value = new JSON.Array();
			Assert.AreEqual("[]", value.ToString());
		}
		
		[Test()]
		public void ArrayOneElement()
		{
			var value = new JSON.Array();
			value.Add(null);
			Assert.AreEqual("[null]", value.ToString());
		}
		
		[Test()]
		public void ArrayManyElements()
		{
			var value = new JSON.Array();
			value.Add(null);
			value.Add(true);
			value.Add("a");
			Assert.AreEqual("[null,true,\"a\"]", value.ToString());
		}
		
		[Test()]
		public void ArrayInnerArray()
		{
			var value = new JSON.Array();
			value.Add(new JSON.Array());
			value.Add(new JSON.Array());
			Assert.AreEqual("[[],[]]", value.ToString());
		}
		
		[Test()]
		public void ObjectEmpty()
		{
			var value = new JSON.Object();
			Assert.AreEqual("{}", value.ToString());
		}
		
		[Test()]
		public void ObjectOneField()
		{
			var value = new JSON.Object();
			value["test"] = null;
			Assert.AreEqual("{\"test\":null}", value.ToString());
		}
		
		[Test()]
		public void ObjectManyFields()
		{
			var value = new JSON.Object();
			value["string"] = "hello";
			value["boolean"] = true;
			value["null"] = null;
			Assert.AreEqual("{\"string\":\"hello\",\"boolean\":true,\"null\":null}", value.ToString());
		}
		[Test()]
		public void ObjectInnerObject()
		{
			
			var outer = new JSON.Object();
			var inner = new JSON.Object();
			outer["inner"] = inner;
			inner["prop"] = null;
			
			Assert.AreEqual("{\"inner\":{\"prop\":null}}", outer.ToString());
		}
		
		[Test()]
		public void NumberSimple()
		{
			var value = (JSON.Number)1;
			Assert.AreEqual("1", value.ToString());
		}
		
		[Test()]
		public void NumberNegative()
		{
			var value = (JSON.Number) (-1);
			Assert.AreEqual("-1", value.ToString());
		}
		
		[Test()]
		public void NumberDecimal()
		{
			var value = (JSON.Number)1.5;
			Assert.AreEqual("1.5", value.ToString());
		}
		
		[Test()]
		public void NumberFloat()
		{
			var value = (JSON.Number) 1.5e-22;
			Assert.AreEqual("1.5e-22", value.ToString().ToLower());
		}
		
		[Test()]
		public void NumberFloatDoubleNegation()
		{
			var value = (JSON.Number) (-1.2e-20);
			Assert.AreEqual("-1.2e-20", value.ToString().ToLower());
		}
	}
}
